package iceberg;

import iceberg.constraints.IConstraintResult;
import iceberg.domain.Unit;
import iceberg.rules.RuleDispatcher;
import oet.CentralStorage;
import oet.io.DirectoryScanner;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public final class OetAdapter {

	private static final Logger LOG = LoggerFactory.getLogger(OetAdapter.class);

	private OetAdapter() {
	}

	public static void main(String[] args) {
		RuleDispatcher dispatcher = new RuleDispatcher();
		DirectoryScanner scanner = new DirectoryScanner();
		scanner.scanDirectory(new File(Config.getTestProjectLocation()));

		CentralStorage storage = CentralStorage.getInstance();
		List<IConstraintResult> results = new ArrayList<IConstraintResult>();
		for(oet.domain.Reference reference : storage.getReferences().keySet()) {
			results.addAll(dispatcher.invokeRules(
					new Reference(
							Unit.createClassUnit(reference.getFrom().getItemName()),
							Unit.createClassUnit(reference.getTo().getItemName()))));
		}

		for(IConstraintResult result : results) {
			LOG.error("Error: " + result.getType().getName());
		}

	}
}
